<template>
	<view class="content" :style="{background: `url(${imgPath}storage/home/home_bg.png)`,backgroundSize: '100%'}">
		<view class="box">
			<view class="header-box">
				<view class="goods">
					<view class="img">
						<u--image :showLoading="true" :src="info.product_img" width="180rpx" height="180rpx"></u--image>
					</view>
					<view class="text">
						<view class="top">
							{{info.product_name}}
						</view>
						<view class="bottom">
							X 1
						</view>
					</view>
					<view class="num">
						¥{{info.price}}
					</view>
				</view>
				<view class="line"></view>
				<view class="address-box">
					<view class="left-box">
						<u--image :showLoading="true" :src="imgPath + 'storage/home/icon-cart.png'" width="34rpx"
							height="30rpx"></u--image>
						<!-- icon-cart <u-icon name="red-packet-fill" size="34" color="#878787"
							@click="replication(info.order_no)"></u-icon> -->
					</view>
					<view class="right-box">
						<view class="info-box">
							<!-- <text class="big-text">厦门市</text> -->
							<text class="small-text">{{massageinfo}}</text>
						</view>
						<view class="icon-box">
							<u-icon name="arrow-right" size="15" color="#878787"
								@click="replication(info.order_no)"></u-icon>
						</view>
					</view>
				</view>
			</view>

			<view class="service-box" @click="linkDetail(0)">
				<view class="left-box">我要退货退款</view>
				<view class="right-box">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/icon-right.png'" width="40rpx"
						height="40rpx"></u--image>
				</view>
			</view>
			<view class="service-box" @click="linkDetail(1)">
				<view class="left-box">我要换货</view>
				<view class="right-box">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/icon-right.png'" width="40rpx"
						height="40rpx"></u--image>
				</view>
			</view>
		</view>

		<uni-popup ref="popup" type="center">
			<view class="pay-popup">
				<view class="close" @click="close">
					<u-icon name="close" color="#fff" size="28" bold></u-icon>
				</view>
				<view class="successful-img">
					<u--image :showLoading="true" :src="imgPath + 'storage/home/paysuccessful.png'" width="192rpx"
						height="40rpx"></u--image>
				</view>
				<view class="popup-box"
					:style="{background: `url(${imgPath}storage/home/paybg.png)`,backgroundSize: '100%'}">
					<view class="ok-img">
						<u--image :showLoading="true" :src="imgPath + 'storage/home/payok.png'" width="150rpx"
							height="152rpx"></u--image>
					</view>
					<view class="text">
						您已成功支付，可到个人中心查看！
					</view>
					<view class="btns">
						<view class="left-btn" @click="goHome">
							返回首页
						</view>
						<view class="right-btn" @click="showDetail">
							查看订单
						</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	import {
		pay
	} from '@/utils/index.js'
	export default {
		data() {
			return {
				imgPath: this.$store.state.user.baseURL,
				info: {},
				id: '',
				massageinfo: ''
			};
		},
		onLoad(e) {
			this.id = e.id
			this.getInfo()
			this.getsynqueryindex()
		},
		methods: {
			getsynqueryindex() {
				this.$api.synqueryindex({
					nu: this.info.nu
				}).then(res => {
					this.massageinfo = res.data.message
				})
			},
			getInfo() {
				this.$api.productOrderinfo({
					order_id: this.id
				}).then(res => {
					this.info = res.data
				})
			},
			linkDetail(type) {
				uni.navigateTo({
					url: '/subpackageA/orderservice/servicedetail?id=' + this.id + "&type=" + type
				})
			},
			replication(text) {
				uni.setClipboardData({
					data: text,
					success: function() {
						console.log('复制成功');
					}
				});
			},
			payOrder(id) {
				pay(id, 3, (() => {
					this.getInfo(id)
					this.open()
				}))
			},
			cancelOrder(order_id) {
				this.$api.productOrdercancel({
					order_id
				}).then(res => {
					this.getInfo()
				})
			},
			delOrder(order_id) {
				this.$api.productOrderdel({
					order_id
				}).then(res => {
					let pages = getCurrentPages()
					let prevPage = pages[pages.length - 2]
					if (prevPage.$vm.updata != undefined) prevPage.$vm.updata()
					uni.navigateBack({
						delta: 1
					})
				})
			},
			buyAgain(obj) {
				console.log(obj);
				this.$api.productOrdercreate({
					product_id: obj.product_id,
					remark: obj.remark,
					address_id: obj.address_id
				}).then(res => {
					pay(res.data.order_id, 3)
				})
			},
			close() {
				this.$refs.popup.close()
			},
			open() {
				this.$refs.popup.open()
			},
			goHome() {
				this.close()
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			showDetail() {
				this.close()
			}
		}
	}
</script>

<style lang="scss">
	.content {
		min-height: 100vh;
		z-index: -1;
	}

	.box {
		padding: 20rpx 30rpx 0 30rpx;
	}

	.header-box,
	.information,
	.order {
		background: #FEF1DC;
		border-radius: 20rpx;
		margin-bottom: 16rpx;
		box-sizing: border-box;
	}

	.header-box {
		padding: 0 30rpx;

		.address-box {
			padding: 44rpx 0 52rpx;
			display: flex;

			.left-box {
				margin-right: 24rpx;
				flex-direction: column;
				align-items: center;
				align-self: center;
			}

			.right-box {
				display: flex;
				justify-content: space-between;
				flex: 1;

				.info-box {
					font-size: 28rpx;
					line-height: 36rpx;

					.big-text {
						color: #111111;
						margin-right: 20rpx;
					}

					.small-text {
						color: #999;
						font-size: 24rpx;
					}
				}

				.icon-box {
					display: flex;
					flex-direction: column;
					align-items: center;
					align-self: center;
					margin-left: 6rpx;
				}
			}
		}

		.goods {
			display: flex;
			padding: 40rpx 0 30rpx;
		}

		.line {
			height: 1rpx;
			background-color: #d3d3d3;
			transform: scaleY(0.5);
		}

		.img {
			width: 180rpx;
			height: 180rpx;
			margin-right: 20rpx;
		}

		.text {
			flex: 1;
			padding: 0 0 0 10rpx;

			.top {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #111111;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
			}

			.bottom {
				padding-top: 10rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 400;
				font-size: 24rpx;
				color: #AAAAAA;
				line-height: 34rpx;
				text-align: left;
				font-style: normal;
			}
		}

		.num {
			width: 150rpx;
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 36rpx;
			color: #D06122;
			line-height: 180rpx;
			text-align: right;
			font-style: normal;
		}
	}

	.service-box {
		display: flex;
		justify-content: space-between;
		padding: 40rpx 30rpx;
		background: #FEF1DC;
		border-radius: 20rpx;
		margin-bottom: 16rpx;
		box-sizing: border-box;

		.left-box {
			color: #111111;
			font-size: 28rpx;
		}

		.right-box {
			display: flex;
			flex-direction: column;
			align-items: center;
			align-self: center;
			margin-left: 6rpx;
		}
	}

	.information {
		height: 284rpx;
		padding: 30rpx;

		.title {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}

		.information-box {
			padding-top: 30rpx;

			.item {
				display: flex;
				padding-bottom: 16rpx;

				.lable {
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}

	.order {
		height: 330rpx;
		padding: 30rpx;

		.title {
			font-family: PingFangSC, PingFang SC;
			font-weight: 500;
			font-size: 28rpx;
			color: #111111;
			line-height: 40rpx;
			text-align: left;
			font-style: normal;
		}

		.order-box {
			padding-top: 30rpx;

			.item {
				display: flex;
				padding-bottom: 16rpx;

				.lable {
					width: 180rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #999999;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}

				.text {
					font-family: PingFangSC, PingFang SC;
					font-weight: 400;
					font-size: 24rpx;
					color: #111111;
					line-height: 34rpx;
					text-align: left;
					font-style: normal;
				}
			}
		}
	}

	.button-box {
		box-sizing: border-box;
		position: absolute;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 124rpx;
		background: #FEF1DC;
		padding: 0 30rpx;
		display: flex;
		justify-content: space-between;
		align-items: center;

		.left {
			font-family: PingFangSC, PingFang SC;
			font-weight: 600;
			font-size: 30rpx;
			color: #6A2D0A;
			line-height: 42rpx;
			text-align: left;
			font-style: normal;
		}

		.right {
			display: flex;

			.left-btn,
			.right-btn {
				width: 220rpx;
				height: 84rpx;
				border-radius: 42rpx;
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 30rpx;
				line-height: 84rpx;
				text-align: center;
				font-style: normal;
			}

			.left-btn {
				color: #D06122;
				border: 2rpx solid #D06122;
			}

			.right-btn {
				color: #FFFFFF;
				margin-left: 20rpx;
				background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
			}
		}
	}

	.pay-popup {
		width: 570rpx;
		height: 636rpx;
		background: linear-gradient(270deg, #FFFFFF 0%, #F2D8AE 100%);
		border-radius: 40rpx;
		box-sizing: border-box;

		.close {
			width: 90rpx;
			height: 90rpx;
			position: absolute;
			bottom: -150rpx;
			left: 50%;
			transform: translateX(-50%);
			border: 8rpx solid white;
			border-radius: 50%;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.successful-img {
			height: 120rpx;
			display: flex;
			justify-content: center;
			align-items: center;
		}

		.popup-box {
			width: 570rpx;
			height: 516rpx;
			background-size: 100% 100%;
			display: flex;
			flex-direction: column;
			align-items: center;

			.ok-img {
				padding-top: 56rpx;
			}

			.text {
				font-family: PingFangSC, PingFang SC;
				font-weight: 500;
				font-size: 28rpx;
				color: #999999;
				line-height: 40rpx;
				text-align: left;
				font-style: normal;
				padding-top: 44rpx;
			}

			.btns {
				padding-top: 80rpx;
				display: flex;
				justify-content: space-between;
				width: 450rpx;

				.left-btn {
					width: 200rpx;
					height: 84rpx;
					background: #A3A3A3;
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}

				.right-btn {
					width: 200rpx;
					height: 84rpx;
					background: linear-gradient(270deg, #EA6F29 0%, #FAAA7D 100%);
					border-radius: 16rpx;
					font-family: PingFangSC, PingFang SC;
					font-weight: 500;
					font-size: 30rpx;
					color: #FFFFFF;
					line-height: 84rpx;
					text-align: center;
					font-style: normal;
				}
			}
		}
	}
</style>